<script setup>
import { ref } from "vue";
import StatCard from "../components/StatCard.vue";
import VisitChart from "../components/VisitChart.vue";
import PieChart from "../components/PieChart.vue";

const stats = ref({
  totalUsers: 1680,
  totalVisits: 1568,
});

// 添加时间段选择
const timeRanges = ref([
  { label: '本年', active: true },
  { label: '本季度', active: false },
  { label: '本月', active: false },
  { label: '本周', active: false }
]);

// 添加图表数据类型
const chartTypes = ref([
  { label: '未完成日程', color: '#1a73e8' },
  { label: '已完成日程', color: '#dc4e41' },
  { label: '重要程度', color: '#ffd700', type: 'line' }
]);

const pieData = ref([
  { value: 40, name: '已处理', color: '#1a73e8' },
  { value: 35, name: '进行中', color: '#dc4e41' },
  { value: 25, name: '未处理', color: '#ffd700' }
]);
</script>

<template>
  <div class="dashboard">
    <TopNav />
    <div class="dashboard-content">
      <div class="stats-container">
        <StatCard
          title="总人数"
          :value="stats.totalUsers"
          icon="👥"
          color="#1a73e8"
        />
        <StatCard
          title="访问次数"
          :value="stats.totalVisits"
          icon="👁"
          color="#dc4e41"
        />
        <div class="status-card">
          <h3>订单处理状态统计</h3>
          <div class="status-chart">
            <div class="pie-chart">
              <PieChart :data="pieData" />
            </div>
            <div class="status-legend">
              <div class="legend-item">
                <span class="dot" style="background: #1a73e8"></span>
                <span>已处理</span>
              </div>
              <div class="legend-item">
                <span class="dot" style="background: #dc4e41"></span>
                <span>进行中</span>
              </div>
              <div class="legend-item">
                <span class="dot" style="background: #ffd700"></span>
                <span>未处理</span>
              </div>
            </div>
          </div>
        </div>
        <div class="weather-card">
          <div class="weather-info">
            <div class="weather-header">
              <h3>早上好，欢迎进入飞廉系统</h3>
              <div class="weather-icon">🌤️</div>
            </div>
            <div class="weather-details">
              <div class="date-group">
                <span class="month">2月</span>
                <span class="date">16</span>
              </div>
              <div class="time-group">
                <span class="day">星期四</span>
                <span class="temp">23°C</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="chart-section">
        <div class="chart-header">
          <div class="time-ranges">
            <button 
              v-for="range in timeRanges" 
              :key="range.label"
              :class="{ active: range.active }"
              class="time-btn"
            >
              {{ range.label }}
            </button>
          </div>
          <div class="chart-legend">
            <div 
              v-for="type in chartTypes" 
              :key="type.label"
              class="legend-item"
            >
              <span 
                class="legend-color"
                :style="{ background: type.color }"
              ></span>
              <span>{{ type.label }}</span>
            </div>
          </div>
        </div>
        <VisitChart class="visit-chart" />
      </div>
    </div>
  </div>
</template>

<style scoped>
.dashboard {
  height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  background: var(--bg-secondary);
}

.dashboard-content {
  flex: 1;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  overflow-y: auto;
}

.stats-container {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(200px, 1fr) minmax(250px, 1.2fr) minmax(250px, 1.2fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 0.5rem;
  border-radius: 8px;
  background: var(--bg-secondary);
}

.status-card, .weather-card {
  min-height: 180px;
  display: flex;
  flex-direction: column;
}

.status-card h3 {
  margin: 0 0 1rem 0;
  color: #333;
}

.status-chart {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.pie-chart {
  width: 120px;
  height: 120px;
  position: relative;
}

.status-legend {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.legend-item {
  display: flex;
  align-items: center;
  padding: 0.3rem 0.8rem;
  border-radius: 15px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.legend-item:hover {
  background: #f5f6fa;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.weather-card {
  background: linear-gradient(135deg, #1a73e8, #4285f4);
  color: white;
  padding: 1.5rem;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 180px;
  position: relative;
  overflow: hidden;
}

.weather-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.weather-icon {
  font-size: 2.5rem;
  margin-left: 1rem;
}

.weather-info h3 {
  margin: 0;
  font-weight: 500;
  font-size: 1.2rem;
  line-height: 1.4;
}

.weather-details {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.date-group {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.month {
  font-size: 1.2rem;
  opacity: 0.9;
}

.date {
  font-size: 2.5rem;
  font-weight: bold;
  line-height: 1;
}

.time-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.day {
  font-size: 1.1rem;
  opacity: 0.9;
}

.temp {
  font-size: 1.8rem;
  font-weight: 500;
}

/* 添加一些装饰效果 */
.weather-card::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 200px;
  height: 200px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  pointer-events: none;
}

.weather-card::after {
  content: '';
  position: absolute;
  bottom: -30%;
  left: -30%;
  width: 160px;
  height: 160px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 50%;
  pointer-events: none;
}

.chart-section {
  background: var(--bg-primary);
  padding: 1.2rem;
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  min-height: 450px;
  width: 100%;
  margin: 0;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.2rem;
  padding: 0 0.5rem;
}

.time-ranges {
  display: flex;
  gap: 0.8rem;
}

.time-btn {
  padding: 0.5rem 1.2rem;
  border: 1px solid #e0e0e0;
  background: var(--bg-primary);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.time-btn:hover {
  border-color: #1a73e8;
  color: #1a73e8;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(26, 115, 232, 0.1);
}

.time-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(26, 115, 232, 0.2);
}

.time-btn.active:hover {
  background: #1557b0;
  transform: translateY(-1px);
}

.chart-legend {
  display: flex;
  gap: 2.5rem;
}

.legend-color {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.5rem;
}

.visit-chart {
  height: 380px;
}

.status-card {
  background: var(--bg-primary);
  padding: 1.2rem;
  border-radius: 12px;
  box-shadow: var(--card-shadow);
}

.status-card h3 {
  color: var(--text-primary);
}

.legend-item {
  color: var(--text-secondary);
}

.legend-item:hover {
  background: var(--hover-bg);
}

.chart-section {
  background: var(--bg-primary);
  box-shadow: var(--card-shadow);
}

/* 修改图表区域的文字颜色 */
.chart-legend .legend-item {
  color: var(--text-secondary);
}

/* 修改天气卡片在暗色模式下的样式 */
.weather-card {
  background: linear-gradient(135deg, var(--primary-color), #4285f4);
}

/* 修改图表区域的背景和文字 */
:root[data-theme='dark'] .visit-chart {
  filter: brightness(0.9);
}
</style>
